package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmployeeMapper {
    /**
     * 根据传进来的employee中的username查询对象
     *
     * @param employee
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee selectByUsername(Employee employee);

    @Insert("INSERT INTO employee VALUES (null, #{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber},1, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void save(Employee employee);


    /**
     * 带模糊查询的查询所有
     *
     * @param name
     * @return
     */
    @Select("select * from employee where name like concat(\"%\",ifnull(#{name},\"\"),\"%\")")
    //ifnull(#{name},'')是mysql中的函数,当第一个参数为null时,返回值将是第二个参数指定的值,用于替代xml文件中写动态SQL
    //此处当#{name}为null时,即给出查询条件时,concat("%",ifnull(#{name},''),"%")的结果将是"%%",表示任意字符也即不限定条件查询所有(like  某个占位符  模糊匹配可用 _ 匹配单个字符, % 匹配任意个字符),而当#{name}不为空时,结果将为"%XXX%",即进行模糊查询
    List<Employee> selectAllByName(String name);


    /**
     * 动态SQL实现,根据id修改 status username name phone sex id_number
     */
    void updateStatus(Employee employee);

    @Select("select * from employee where id = #{id}")
    Employee selectAllById(Integer id);

}
